<template>
  <el-dialog
    v-el-drag-dialog
    title="处理确认"
    :visible.sync="visible"
    width="600px"
    @closed="reset"
  >
    <el-form ref="dataForm" class="form" :model="temp" label-position="right" label-width="80px">
      <el-form-item label="责任机构:">
        <el-input v-model="temp.orgName" disabled />
      </el-form-item>
      <el-form-item label="处理人:">
        <el-input v-model="temp.userName" disabled />
      </el-form-item>
      <el-form-item label="处理结果:" class="block">
        <el-radio-group v-if="isExist === 0" v-model="radio" @change="radioChange">
          <el-radio label="已解决">已解决</el-radio>
          <el-radio label="不能解决,已汇报站长处理">不能解决,已汇报站长处理</el-radio>
        </el-radio-group>
        <el-radio-group v-else v-model="radio" @change="radioChange">
          <el-radio v-for="item in commonKeysInfoList" :key="item.keyId" :value="item.keyId" :label="item.keyName">{{ item.keyName }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item prop="marker2" class="block">
        <el-input v-model="temp.marker2" type="textarea" :rows="3" maxlength="255" show-word-limit />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        取消
      </el-button>
      <el-button :loading="$loadingPlugin.submit" type="primary" @click="success">
        确定
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { queryDealConfirmRepairOrder, queryRepairOrderBackDealParam } from '@/api'

  export default {
    name: 'deal-confirm',
    data() {
      return {
        visible: false,
        isExist: 0,
        commonKeysInfoList: [],
        temp: {
          marker2: ''
        },
        radio: ''
      }
    },
    methods: {
      open(temp) {
        this.getDefaultData()
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            this.temp = Object.assign(this.temp, temp)
          }
        })
      },
      async getDefaultData() {
        const res = await queryRepairOrderBackDealParam()
        this.isExist = Number(res.data.isExist)
        this.commonKeysInfoList = JSON.parse(res.data.commonKeysInfoList)
      },
      radioChange(value) {
        this.temp.marker2 = value
      },
      success() {
        this.$refs.dataForm.validate(valid => {
          if (!valid) return
          const params = {
            repairCode: this.temp.repairCode,
            orgId: this.temp.orgId,
            orgSNNo: this.temp.orgSNNo,
            orgName: this.temp.orgName,
            userId: this.temp.userId,
            userName: this.temp.userName,
            marker2: this.temp.marker2
          }
          this.submit(params)
        })
      },
      async submit(params) {
        await queryDealConfirmRepairOrder(params)
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '操作成功!',
          type: 'success',
          duration: 2000
        })
      },
      reset() {
        this.isExist = 0
        this.commonKeysInfoList = []
        this.temp = {
          marker2: ''
        }
        this.radio = ''
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
.form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  & /deep/ .el-form-item {
    width: 50%;
    .el-form-item__content > .el-select {
      width: 100%;
    }
  }
  .block {
    width: 100%;
  }
}
</style>
